Skip to content

Structured output#5

Merged
david-crespo merged 7 commits into
mainfrom
structured-output
Apr 24, 2026
Merged

Structured output#5
david-crespo merged 7 commits into
mainfrom
structured-output

Conversation

@david-crespo
Copy link
Copy Markdown
Owner

@david-crespo david-crespo commented Apr 24, 2026

Adds --output-schema/-o for structured output across all providers (except OpenAI in background mode), using ArkType as the user-facing schema language.

The secret is https://arktype.io/, which lets you express schemas in a very concise form, which can then be converted programmatically to the JSON Schema format the SDKs want. We don't have to eval anything, we just pare with JSON5.

Provider-specific quirks: object schemas are closed, OpenAI strict mode gets all fields marked required, and non-object roots are wrapped as { value: ... } then unwrapped before printing.

Examples

ai -o "boolean" "is 17 prime?"
# true

ai -o "'yes' | 'no'" "is Paris in France?"
# yes

ai -o '{ urgent: "boolean", reason: "string" }' 'is this urgent? server is down'
# {
#   "urgent": true,
#   "reason": "The service is unavailable."
# }

ai -o "string[]" "give three terse git commit message verbs"
# ["fix","add","remove"]

@david-crespo david-crespo marked this pull request as ready for review April 24, 2026 21:34
@david-crespo david-crespo merged commit 355c690 into main Apr 24, 2026
1 check passed
@david-crespo david-crespo deleted the structured-output branch April 25, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant